package com.z.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.z.admin.entity.Blog;
import com.z.admin.entity.Tag;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author z
 * @since 2022-04-11
 */
public interface BlogMapper extends BaseMapper<Blog> {
    @Select("select count(id) from (select DISTINCT b.id from t_blog b left join t_blog_tags bt on b.id=bt.blogs_id ${whereSql} )t")
    Integer conutByMap(String whereSql);

    @Select("select distinct b.* from t_blog b left join t_blog_tags bt on b.id=bt.blogs_id ${where} order by b.id limit #{startPosition} , #{limit}")
    List<Blog> findPageByWhereSql(String where, Integer startPosition, Integer limit);

    @Select("select t.* from t_tag t left join t_blog_tags bt on t.id=bt.tags_id where bt.blogs_id = #{id}")
    List<Tag> getTags(Long id);
    @Update("update t_blog set views=views+1 where id=#{id}")
    void updateViewsById(Long id);
}
